home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*------------------------------------------------------------------------------
- * oort.c oort main routine.
- *
- * $Revision: 1.7 $ $Date: 1994/02/07 23:58:31 $
- *
- * Chris Fouts - April, 1993.
- *
- *----------------------------------------------------------------------------*/
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <sys/param.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <bstring.h>
- #include <netinet/in.h>
- #include <netdb.h>
- #include <ctype.h>
- #include <arpa/inet.h>
- #include <gl/device.h>
-
- #include <pf.h>
-
- #include "oort.h"
- #include "configure.h"
- #include "load.h"
- #include "gameio.h"
- #include "dashboard.h"
- #include "background.h"
- #include "vehicle.h"
- #include "input.h"
- #include "radar.h"
- #include "text.h"
- #include "validate.h"
- #include "multicast.h"
- #include "explosion.h"
- #include "sound.h"
-
- #define LASER_MASK 0x08
-
- pfLight *Sun;
-
- Object starObj ;
- Object helpObj ;
-
- char *basename = "oort" ;
- char playerName[NAMELEN] ;
- pfVec3 groundColor = { 0.54f, 0.50f, 0.36f } ;
- pfVec3 vehicleColor ;
- pfVec3 teamColor[N_TEAMS] = {
- { 1.00f, 1.00f, 1.00f },
- { 1.00f, 0.25f, 0.25f },
- { 0.25f, 1.00f, 0.25f },
- { 0.25f, 0.25f, 1.00f },
- } ;
- static char *defaultConfigText[6] = {
- "terrainColor: 0.54 0.50 0.36\n",
- "textLines: 12\n",
- "teamColorA: 1.00 1.00 1.00\n",
- "teamColorB: 1.00 0.25 0.25\n",
- "teamColorC: 0.25 1.00 0.25\n",
- "teamColorD: 0.25 0.25 1.00\n",
- } ;
-
- static unsigned short cursorBitMap1[] = {
- 0xc003, 0xe007, 0x700e, 0x381c,
- 0x1c38, 0x0e70, 0x0660, 0x0000,
- 0x0000, 0x0660, 0x0e70, 0x1c38,
- 0x381c, 0x700e, 0xe007, 0xc003,
- } ;
- static unsigned short cursorBitMap2[] = {
- 0x0000, 0x4002, 0x2004, 0x1008,
- 0x0810, 0x0420, 0x0240, 0x0000,
- 0x0000, 0x0240, 0x0420, 0x0810,
- 0x1008, 0x2004, 0x4002, 0x0000,
-
- 0xc003, 0xa005, 0x500a, 0x2814,
- 0x1428, 0x0a50, 0x0420, 0x0000,
- 0x0000, 0x0420, 0x0a50, 0x1428,
- 0x2814, 0x500a, 0xa005, 0xc003,
- } ;
-
- typedef void (*MoveFunction)( void ) ;
-
- PacketFunction readPackets ;
- PacketFunction writePackets ;
- MoveFunction moveMe ;
-
- float frameRate = 15.0f ;
- int initialVol = 11 ;
- int showHelp = 0 ;
- int selfStatus ;
- int newSelfStatus ;
- int networking ;
- int nTextLines = 12 ;
- int landing = 0 ;
- int selfDestruct = 0 ;
- float selfDestructTime ;
- float selfDestructAlarmTime ;
- Motion motion ;
- GeoFont *helvFont ;
- GeoFont *helpFont ;
- ViewPort headingVP ;
- ViewPort radarVP ;
- ViewPort indicatorVP ;
- Wheel wheel[3] ;
- Player player[MAXPLAYERS] ;
- int activity[MAXPLAYERS] ;
- pfDCS *trike[MAXPLAYERS] ;
- pfGroup *trikeSwitch[MAXPLAYERS] ;
- pfGroup *shield ;
- pfGroup *pShield[MAXPLAYERS] ;
- pfGroup *vehicle[N_TEAMS] ;
- pfMatrix playerMatrix[MAXPLAYERS] ;
- float deadTime[MAXPLAYERS] ;
- pfVec3 velocity[MAXPLAYERS] ;
- pfVec3 acceleration[MAXPLAYERS] ;
- pfMatrix selfMatrix ;
- pfVec3 up ; /* Up rel to vehicle. */
- pfVec3 ahead ; /* Ahead rel to vehicle. */
- pfVec3 right ; /* Right rel to vehicle. */
- pfVec3 worldUp ; /* Up rel to oort. */
- float speed ;
- float shields ;
- float power ;
- float laser ;
- float cloak ;
- int cloakOn ;
- float laserCharge ;
- float shieldRegenRate ;
- float laserRegenRate ;
- float cloakRegenRate ;
- float gameTime ; /* elapsed time for entire game */
- float eTime ; /* elapsed time since last frame */
- float idleStartTime = 0.0f ;
- int stayInProgram = 1 ;
- int showStats = 0 ;
- int leftMouseHit = 0 ;
- int middleMouseDown = 0 ;
- int rightMouseHit = 0 ;
- int timeToLive = NG_DEFAULT_TTL ;
- float mouseX ;
- float mouseY ;
- float pickX ;
- float pickY ;
- float latitude = 0.0f ;
- float longitude = 0.0f ;
- int numberPlayers = 1 ;
- float mvOverlayH = 1.0f ;
- float mvOverlayW = 1.0f ;
- float pitch ;
- float roll ;
- int inFd = -1 ;
- int outFd = -1 ;
- char *inName = NULL ;
- char *outName = NULL ;
- int demoMode = 0 ;
-
- static pfChannel *mainChan ;
- static pfChannel *diagChan ;
- static pfGeoSet *starGSet ;
- static pfGroup *terrain ;
- static pfGroup *vehicleGroup ;
- static pfGroup *terrainAndVehicles ;
- static pfScene *mainScene ;
- static pfSphere *vehicleBoundingSphere ;
- static pfBox hitBox ;
- static pfMatrix hitMatrix ;
-
- static int trikeHit ;
- static int checkTrike ;
-
- extern int roidZoom ;
- extern int debugOn ;
- extern float topSpeed ;
- extern float shieldFactor ;
- extern float laserFactor ;
- extern float engineRate ;
- extern float cloakRate ;
- extern float solarRate ;
- extern ViewPort mainVP ;
- extern int terrainTextured ;
-
-
-
- /* BEGIN PROTOTYPES -S oort.c */
- static void checkGraphicsHw( void ) ;
- static void checkMinReqs( void ) ;
- static int compareScores( const void *p1, const void *p2 ) ;
- static void CullDiagChannel( pfChannel *channel, void *data ) ;
- static void demoMainLoop( void ) ;
- static void demoPostProcessPlayers( void ) ;
- static void displayHelp( void ) ;
- static void distributePower( void ) ;
- static void doPick( pfNode *root, long mode, long mask, pfHit **hits[] ) ;
- static void drawMainChannel( pfChannel *channel, void *data ) ;
- static void drawOrbitalFortressStrikes( void ) ;
- static void drawPitchRollIndicator( void ) ;
- static void drawStaticDisplay( void ) ;
- static void drawStaticScreen( pfChannel *channel, void *data ) ;
- static void drawTitle( void ) ;
- static void fireLaser( void ) ;
- static long fireLaserPostTravCB( pfTraverser *trav, void *data ) ;
- static long fireLaserPreTravCB( pfTraverser *trav, void *data ) ;
- static void getLatLong( void ) ;
- static void groundIntersectionSetup( pfGroup *root ) ;
- static void initCursor( void ) ;
- static void initEnemies( void ) ;
- static void initSelf( void ) ;
- static void initShield( void ) ;
- static void initStuff( void ) ;
- static void loadCustom( void ) ;
- static void mainLoop( void ) ;
- static Object makeHelpOverlay( void ) ;
- static void moveArgs( int argc, char **argv, int start, int n ) ;
- static void noConfigFile( char *name ) ;
- static void openPipe( pfPipe *p ) ;
- static void parseArgs( int *argc, char **argv ) ;
- static long pickDiscFunc( pfHit *hit ) ;
- static int pickLandingSite( pfVec3 landingSite ) ;
- static void pickPlayer( void ) ;
- static void postProcessPlayers( void ) ;
- static int readColor( char *s, pfVec3 v ) ;
- static void repaintCompass( void ) ;
- static void setupChannels( pfPipe *p ) ;
- static void updateViewGround( void ) ;
- static void updateViewInOrbit( void ) ;
- static void usage( void ) ;
- static void vecMultMatInPlace( pfVec4 v, pfMatrix m ) ;
- /* END PROTOTYPES -S oort.c */
-
-
-
- #define HALFTONE_PATTERN 1
- static unsigned short halftone[] = {
- 0xaaaa, 0x5555, 0xaaaa, 0x5555,
- 0xaaaa, 0x5555, 0xaaaa, 0x5555,
- 0xaaaa, 0x5555, 0xaaaa, 0x5555,
- 0xaaaa, 0x5555, 0xaaaa, 0x5555,
- } ;
- #define STATIC_PATTERN_0 2
- #define STATIC_PATTERN_1 3
- #define STATIC_PATTERN_2 4
- static unsigned short staticPattern[3][16] = {
- {
- 0xfc00, 0xfc00, 0x003f, 0x003f,
- 0x0fc0, 0x0fc0, 0xf003, 0xf003,
- 0x00fc, 0x00fc, 0x3f00, 0x3f00,
- 0xc00f, 0xc00f, 0x03f0, 0x03f0,
- },
- {
- 0x03f0, 0x03f0, 0xfc00, 0xfc00,
- 0x003f, 0x003f, 0x0fc0, 0x0fc0,
- 0xf003, 0xf003, 0x00fc, 0x00fc,
- 0x3f00, 0x3f00, 0xc00f, 0xc00f,
- },
- {
- 0xc00f, 0xc00f, 0x03f0, 0x03f0,
- 0xfc00, 0xfc00, 0x003f, 0x003f,
- 0x0fc0, 0x0fc0, 0xf003, 0xf003,
- 0x00fc, 0x00fc, 0x3f00, 0x3f00,
- },
- } ;
- static long staticColor[] = { 0x00404040, 0x00808080, 0x00c0c0c0 } ;
-
-
-
- /*------------------------------------------------------------------------------
- * Print usage command.
- *----------------------------------------------------------------------------*/
- static void
- usage(
- void
- )
- {
- fprintf( stderr, "Usage: %s [-h] [-i in_file] [-o out_file] "
- "[-n player_name] [-T ttl]\n", basename ) ;
- fprintf( stderr, "Usage: %s [-d demo_file]\n", basename ) ;
- endProgram( 1 ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Main routine.
- *----------------------------------------------------------------------------*/
- void
- main(
- int argc,
- char **argv
- )
- {
- int i ;
-
- /*
- * Load custom options from ~/.oortrc.
- */
- loadCustom() ;
-
- /*
- * Parse command line arguments.
- */
- parseArgs( &argc, argv ) ;
-
- /*
- * Check for minimum system requirements.
- */
- checkMinReqs() ;
-
- /*
- * Initialize Performer
- */
- pfInit();
-
- /*
- * Configure MP mode to use a single process.
- */
- pfMultiprocess( PFMP_APPCULLDRAW ) ;
- pfConfig();
-
- pfNotifyLevel( PFNFY_FATAL ) ;
- mainScene = pfNewScene();
-
- initGeoStates() ;
-
- terrainAndVehicles = pfNewGroup() ;
- pfAddChild( mainScene, terrainAndVehicles ) ;
-
- initStuff() ;
-
- if( ( terrain = loadOortTerrain( "oort.data" ) ) == NULL )
- {
- endProgram( 1 ) ;
- }
- pfAddChild( terrainAndVehicles, terrain ) ;
-
- groundIntersectionSetup( terrain ) ;
-
- vehicleGroup = pfNewGroup() ;
- pfAddChild( terrainAndVehicles, vehicleGroup ) ;
- pfNodeTravMask( vehicleGroup, PFTRAV_ISECT, LASER_MASK | VEHICLE_MASK,
- PFTRAV_SELF | PFTRAV_IS_CACHE, PF_SET ) ;
-
- for( i = 0 ; i < N_TEAMS ; i++ )
- {
- PFCOPY_VEC3( vehicleColor, teamColor[i] ) ;
- if( ( vehicle[i] = loadOortVehicle( "vehicle.data" ) ) == NULL )
- {
- endProgram( 1 ) ;
- }
- }
-
- initShield() ;
-
- initExplosion() ;
-
- pfPhase( PFPHASE_FLOAT ) ;
- pfFrameRate( frameRate ) ;
-
- initSelf() ;
-
- checkGraphicsHw() ;
-
- pfInitClock( 0.0 );
-
- if( demoMode )
- demoMainLoop() ;
- else
- mainLoop() ;
-
- if( networking )
- ngSendQuitPacket() ;
-
- endProgram( 0 ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Open and initialize the pipe.
- *----------------------------------------------------------------------------*/
- static void
- openPipe(
- pfPipe *p
- )
- {
- /*
- * Create a window.
- */
- foreground() ;
- minsize( 400, 300 ) ;
- winopen( "oort" ) ;
-
- pfInitGfx( p ) ;
-
- /*
- * Queue up devices.
- */
- setDevices() ;
-
- /*
- * Set the cursor.
- */
- initCursor() ;
-
- /*
- * Determine window's position.
- */
- getWindowPosition() ;
-
- helvFont = loadFont( "h.oort" ) ;
- setFontSize( helvFont, 0.2f ) ;
-
- pfBasicState() ;
- drawTitle() ;
- swapbuffers() ;
-
- /*
- * Create a light source.
- */
- Sun = pfNewLight( pfGetSharedArena() ) ;
- pfLightPos( Sun, 0.0f, -1.0f, 0.0f, 0.0f ) ;
- pfApplyLModel( pfNewLModel( pfGetSharedArena() ) ) ;
- pfLightOn( Sun ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Channel draw callback - clear, reset sun, and draw.
- *----------------------------------------------------------------------------*/
- static void
- drawMainChannel(
- pfChannel *channel,
- void *data
- )
- {
- float f ;
-
- /* erase framebuffer and draw Earth-Sky model */
- pfClearChan( channel ) ;
-
- /*
- * Get input.
- */
- grabInput() ;
-
- /*
- * Draw stars.
- */
- pfPushMatrix() ;
- translate( motion.cg[0], motion.cg[1], motion.cg[2] ) ;
- callobj( starObj ) ;
- pfPopMatrix() ;
-
- /*
- * Determine world up vector.
- */
- PFCOPY_VEC3( worldUp, motion.cg ) ;
- pfNormalizeVec3( worldUp ) ;
-
- pfLightPos(Sun, 0.0f, -1.0f, 0.0f, 0.0f);
- if( worldUp[1] < 0.0f )
- {
- pfLightAmbient( Sun, -0.60f*worldUp[1], -0.55f*worldUp[1],
- -0.40f*worldUp[2] ) ;
- }
- else
- {
- pfLightAmbient( Sun, 0.0f, 0.0f, 0.0f ) ;
- }
- pfLightOn( Sun ) ;
-
- /*
- * Invoke Performer draw-processing for this frame.
- */
- pfDraw() ;
-
- if( player[SELF].status & ( OORT_ST_SHIELDS | OORT_ST_IDLE_HIT ) )
- {
- setpattern( HALFTONE_PATTERN ) ;
- cpack( 0x00ffff00 ) ;
- clear() ;
- setpattern( 0 ) ;
- }
-
- if( showStats )
- pfDrawChanStats( channel ) ;
-
- pfPushState() ;
- pfBasicState() ;
-
- drawOrbitalFortressStrikes() ;
-
- drawPitchRollIndicator() ;
-
- pfPopState() ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Draw the pitch/roll indicator in the main view.
- *----------------------------------------------------------------------------*/
- static void
- drawPitchRollIndicator(
- void
- )
- {
- float ndr ;
- float ndu ;
- float nda ;
- pfVec3 n ;
- pfVec2 a ;
- pfVec2 b ;
- pfVec2 c ;
-
- pfPushIdentMatrix() ;
- pushviewport() ;
- ortho2( -mvOverlayW, mvOverlayW, -mvOverlayH, mvOverlayH ) ;
- zfunction( ZF_ALWAYS ) ;
- zwritemask( 0x0 ) ;
-
- pfShadeModel( PFSM_FLAT ) ;
-
- cpack( 0x0000ffff ) ;
- rect( -0.2f, -0.2f, 0.2f, 0.2f ) ;
-
- scrmask( indicatorVP.left, indicatorVP.right, indicatorVP.bottom,
- indicatorVP.top ) ;
- if( selfStatus == OORT_ST_IN_ORBIT )
- {
- bgnline() ;
- c[0] = 0.0f ;
- c[1] = 0.2f ;
- v2f( c ) ;
- c[1] = -0.2f ;
- v2f( c ) ;
- endline() ;
- bgnline() ;
- c[0] = 0.2f ;
- c[1] = 0.0f ;
- v2f( c ) ;
- c[0] = -0.2f ;
- v2f( c ) ;
- endline() ;
- }
- else
- {
- PFCOPY_VEC3( n, motion.cg ) ;
- pfNormalizeVec3( n ) ;
-
- nda = PFDOT_VEC3( n, ahead ) ;
- ndr = PFDOT_VEC3( n, right ) ;
- ndu = PFDOT_VEC3( n, up ) ;
-
- pitch = pfArcTan2( nda, ndu ) ;
- if( nda < -0.99999f || nda > 0.99999f )
- {
- roll = 0.0f ;
- }
- else
- {
- roll = pfArcTan2( ndr, ndu ) ;
- }
-
- PFSET_VEC2( a, 0.0f, 0.2f * pitch / -45.0f ) ;
- if( ndu != 0.0f )
- {
- PFSET_VEC2( b, -0.2f, 0.2f * ndr / ndu ) ;
- PFADD_VEC2( c, a, b ) ;
- bgnline() ;
- v2f( c ) ;
- PFSUB_VEC2( c, a, b ) ;
- v2f( c ) ;
- endline() ;
- }
- else
- {
- bgnline() ;
- c[0] = 0.0f ;
- c[1] = 0.2f ;
- v2f( c ) ;
- c[1] = -0.2f ;
- v2f( c ) ;
- endline() ;
- }
-
- if( selfStatus == OORT_ST_ON_GROUND &&
- ( ABS( roll ) > 80.0f || ABS( pitch ) > 80.0f ) )
- {
- postNewMessage( "Overturned." ) ;
- blowUpSelf( 0 ) ;
- }
- }
- zfunction( ZF_LEQUAL ) ;
- zwritemask( 0xffffffff ) ;
-
- popviewport() ;
-
- if( showHelp )
- {
-
- cpack( 0x0000ff00 ) ;
- callobj( helpObj ) ;
-
- }
- pfPopMatrix() ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Channel cull callback - do nothing.
- *----------------------------------------------------------------------------*/
- static void
- CullDiagChannel(
- pfChannel *channel,
- void *data
- )
- {
- /* ARGSUSED */
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Compute the new view.
- *----------------------------------------------------------------------------*/
- static void
- updateViewInOrbit(
- void
- )
- {
- float st ;
- float ct ;
- float sp ;
- float cp ;
- float r = (float)(ASTEROID_RADIUS * 4.0f) ;
- pfVec3 hpr ;
- pfMatrix m ;
- pfVec3 v ;
- static int mode = 0 ;
- static float startX ;
- static float startY ;
- static float zoomFactor = 1.0f ;
-
- if( roidZoom == 1 )
- {
- zoomFactor = 1.05f * zoomFactor ;
- }
- else if( roidZoom == 2 )
- {
- zoomFactor = zoomFactor / 1.05f ;
- }
- r *= zoomFactor ;
-
- /*
- * Rotate asteroid if middle mouse down.
- */
- if( middleMouseDown )
- {
- if( mode )
- {
- longitude += ( mouseX - startX ) * 180.0f * 1.0f ;
- if( longitude < -180.0f )
- {
- longitude += 360.0f ;
- }
- else if( longitude > 180.0f )
- {
- longitude -= 360.0f ;
- }
- latitude += ( mouseY - startY ) * 90.0f * 1.0f ;
- if( latitude < -90.0f )
- {
- latitude = -90.0f ;
- }
- else if( latitude > 90.0f )
- {
- latitude = 90.0f ;
- }
- }
- startX = mouseX ;
- startY = mouseY ;
- }
- mode = middleMouseDown ;
- pfSinCos( longitude, &st, &ct ) ;
- pfSinCos( latitude, &sp, &cp ) ;
- PFSET_VEC3( hpr, longitude, -latitude, 0.0f ) ;
- PFSET_VEC3( motion.cg, r*st*cp, -r*ct*cp, r*sp ) ;
- pfChanView( mainChan, motion.cg, hpr ) ;
-
- if( leftMouseHit && pickLandingSite( motion.cg ) )
- {
- landing = 1 ;
-
- pfNormalizeVec3( motion.cg ) ;
- if( motion.cg[2] < -0.9999f )
- {
- latitude = -90.0f ;
- longitude = 0.0f ;
- }
- else if( 0.9999f < motion.cg[2] )
- {
- latitude = 90.0f ;
- longitude = 0.0f ;
- }
- else
- {
- latitude = pfArcSin( motion.cg[2] ) ;
- longitude = pfArcTan2( motion.cg[0], -motion.cg[1] ) ;
- }
-
- pfSinCos( longitude, &st, &ct ) ;
- pfSinCos( latitude, &sp, &cp ) ;
-
- postNewMessage( "Landing at %.1f, %.1f", latitude, longitude ) ;
-
- PFSCALE_VEC3( motion.cg, (float)(1.1f*ASTEROID_RADIUS),
- motion.cg ) ;
- PFSET_VEC3( motion.vel, 0.0f, 0.0f, 0.0f ) ;
- PFCOPY_VEC3( player[SELF].xyz, motion.cg ) ;
-
- PFSET_VEC3( wheel[FRONT_WHEEL].vel, 0.0f, 0.0f, 0.0f ) ;
- PFSET_VEC3( wheel[RREAR_WHEEL].vel, 0.0f, 0.0f, 0.0f ) ;
- PFSET_VEC3( wheel[LREAR_WHEEL].vel, 0.0f, 0.0f, 0.0f ) ;
- wheel[FRONT_WHEEL].inAir = 1 ;
- wheel[RREAR_WHEEL].inAir = 1 ;
- wheel[LREAR_WHEEL].inAir = 1 ;
-
- selfStatus = OORT_ST_ON_GROUND ;
-
- PFSET_VEC3( right, ct, st, 0.0f ) ;
- PFSET_VEC3( up, st*cp, -ct*cp, sp ) ;
- pfCrossVec3( ahead, up, right ) ;
-
- updateWheels() ;
-
- updateViewGround() ;
- }
- leftMouseHit = 0 ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Compute the new view.
- *----------------------------------------------------------------------------*/
- static void
- updateViewGround(
- void
- )
- {
- pfVec3 u ;
- pfCoord view ;
- pfMatrix m ;
- float s ;
- float c ;
- float d ;
-
- PFCOPY_VEC3( player[SELF].xyz, motion.cg ) ;
- ADDSCALE_VEC3( u, motion.cg, CAR_HEIGHT, up );
-
- selfMatrix[0][0] = right[0] ;
- selfMatrix[0][1] = right[1] ;
- selfMatrix[0][2] = right[2] ;
-
- selfMatrix[1][0] = ahead[0] ;
- selfMatrix[1][1] = ahead[1] ;
- selfMatrix[1][2] = ahead[2] ;
-
- selfMatrix[2][0] = up[0] ;
- selfMatrix[2][1] = up[1] ;
- selfMatrix[2][2] = up[2] ;
-
- selfMatrix[3][0] = u[0] ;
- selfMatrix[3][1] = u[1] ;
- selfMatrix[3][2] = u[2] ;
-
- selfMatrix[0][3] = 0.0f ;
- selfMatrix[1][3] = 0.0f ;
- selfMatrix[2][3] = 0.0f ;
- selfMatrix[3][3] = 1.0f ;
-
- /*
- * Check for bug workaround in pre-Performer_1.2.
- */
- if( selfMatrix[1][2] > 0.999999 )
- {
- selfMatrix[1][2] = 1.0f ;
- }
- else if( selfMatrix[1][2] < -0.999999 )
- {
- selfMatrix[1][2] = -1.0f ;
- }
-
- pfChanViewMat( mainChan, selfMatrix ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Initialize own player structure.
- *----------------------------------------------------------------------------*/
- static void
- initSelf(
- void
- )
- {
- player[SELF].magic = OORT_PLAYER ;
- player[SELF].key = 0 ;
- player[SELF].score = 0 ;
- player[SELF].team = 0 ;
-
- PFSET_VEC3( motion.cg, 0.0f, (float)(-1.1f * ASTEROID_RADIUS), 0.0f ) ;
- PFSET_VEC3( motion.vel, 0.0f, 0.0f, 0.0f ) ;
-
- PFSET_VEC3( wheel[FRONT_WHEEL].vel, 0.0f, 0.0f, 0.0f ) ;
- PFSET_VEC3( wheel[RREAR_WHEEL].vel, 0.0f, 0.0f, 0.0f ) ;
- PFSET_VEC3( wheel[LREAR_WHEEL].vel, 0.0f, 0.0f, 0.0f ) ;
- wheel[FRONT_WHEEL].inAir = 1 ;
- wheel[RREAR_WHEEL].inAir = 1 ;
- wheel[LREAR_WHEEL].inAir = 1 ;
-
- PFSET_VEC3( ahead, 1.0f, 0.0f, 0.0f ) ;
- PFSET_VEC3( right, 0.0f, 0.0f, -1.0f ) ;
- PFSET_VEC3( up, 0.0f, -1.0f, 0.0f ) ;
-
- updateWheels() ;
-
- reset() ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Set up traversal mask for collision.
- *----------------------------------------------------------------------------*/
- static void
- groundIntersectionSetup(
- pfGroup *root
- )
- {
- int mode ;
-
- pfNodeTravMask( root, PFTRAV_ISECT, LASER_MASK | GROUND_MASK,
- PFTRAV_SELF | PFTRAV_DESCEND | PFTRAV_IS_CACHE,
- PF_SET ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Set up main channel and diagnostic channels.
- *----------------------------------------------------------------------------*/
- static void
- setupChannels(
- pfPipe *p
- )
- {
- mainChan = pfNewChan( p ) ;
- pfChanViewport( mainChan, 0.0f, 1.0f, MAIN_VIEW_BOTTOM, 1.0f ) ;
- pfChanNearFar( mainChan, 0.1f, (float)(5.0f*ASTEROID_RADIUS) ) ;
- pfChanFOV( mainChan, 60.0f, -1.0f ) ;
- setMainDrawFunction() ;
-
- diagChan = pfNewChan( p ) ;
- pfChanViewport( diagChan, 0.0f, 1.0f, 0.0f, MAIN_VIEW_BOTTOM ) ;
- pfChanDrawFunc( diagChan, drawDashboardChannel ) ;
- pfChanCullFunc( diagChan, CullDiagChannel ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Determine the latitude and longitude.
- *----------------------------------------------------------------------------*/
- static void
- getLatLong(
- void
- )
- {
- pfVec3 v ;
-
- PFCOPY_VEC3( v, motion.cg ) ;
- pfNormalizeVec3( v ) ;
-
- latitude = pfArcSin( v[2] ) ;
-
- if( v[2] != 1.0f )
- {
- longitude = pfArcTan2( v[0], -v[1] ) ;
- }
- else
- {
- longitude = 0.0f ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Parse command line arguments.
- *----------------------------------------------------------------------------*/
- static void
- parseArgs(
- int *argc,
- char **argv
- )
- {
- int i ;
- int key ;
- int argn = 0 ;
-
- if( ( basename = strrchr( argv[0], '/' ) ) == NULL )
- basename = argv[0] ;
- else
- basename++ ;
-
- for( i = 1 ; i < *argc ; i++ )
- {
- argn++ ;
- if( argv[i][0] == '-' )
- {
- if( !strcmp( argv[i]+1, "i" ) )
- {
- if( inName != NULL )
- usage() ;
- inName = argv[i+1] ;
- moveArgs( *argc, argv, i, 2 ) ;
- *argc -= 2 ;
- i-- ;
- }
- else if( !strcmp( argv[i]+1, "d" ) )
- {
- if( inName != NULL || outName != NULL )
- usage() ;
- inName = argv[i+1] ;
- moveArgs( *argc, argv, i, 2 ) ;
- *argc -= 2 ;
- demoMode = 1 ;
- i-- ;
- }
- else if( !strcmp( argv[i]+1, "T" ) )
- {
- timeToLive = (int)atol( argv[i+1] ) ;
- moveArgs( *argc, argv, i, 2 ) ;
- *argc -= 2 ;
- i-- ;
- }
- else if( !strcmp( argv[i]+1, "o" ) )
- {
- if( demoMode )
- usage() ;
- outName = argv[i+1] ;
- moveArgs( *argc, argv, i, 2 ) ;
- *argc -= 2 ;
- i-- ;
- }
- else if( !strcmp( argv[i]+1, "n" ) )
- {
- strncpy( playerName, argv[i+1],
- sizeof( playerName ) - 1 ) ;
- moveArgs( *argc, argv, i, 2 ) ;
- *argc -= 2 ;
- i-- ;
- }
- else if( !strcmp( argv[i]+1, "h" ) )
- {
- displayHelp() ;
- moveArgs( *argc, argv, i, 1 ) ;
- *argc -= 1 ;
- i-- ;
- }
- else
- {
- usage() ;
- }
- }
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Rearrange argument list.
- *----------------------------------------------------------------------------*/
- static void
- moveArgs(
- int argc,
- char **argv,
- int start,
- int n
- )
- {
- int i ;
- char *t ;
-
- while( n-- )
- {
- t = argv[start] ;
- for( i = start ; i < argc - 1 ; i++ )
- {
- argv[i] = argv[i+1] ;
- }
- argv[argc-1] = t ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * End the program and clean up.
- *----------------------------------------------------------------------------*/
- void
- endProgram(
- int status
- )
- {
- if( outFd > -1 ) {
- close( outFd ) ;
- }
- if( inFd > -1 ) {
- close( inFd ) ;
- }
-
- endSound() ;
-
- pfExit() ;
- exit( status ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Copy over a player structure.
- *----------------------------------------------------------------------------*/
- void
- copyPlayer(
- int k,
- Player *psrc
- )
- {
- bcopy( psrc, &( player[k] ), sizeof( Player ) ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Check for duplicate id's.
- *----------------------------------------------------------------------------*/
- void
- checkId(
- int n
- )
- {
- struct in_addr addr ;
- struct hostent *hp ;
-
- if( !demoMode && player[n].id == player[SELF].id )
- {
- addr.s_addr = player[n].id ;
- hp = gethostbyaddr( &addr, sizeof(addr), AF_INET ) ;
- fprintf( stderr, "\n%s@%s is using your host id!\n\n",
- player[n].name, hp ? hp->h_name : inet_ntoa(addr) ) ;
- endProgram( 1 ) ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Find a player given his id.
- *----------------------------------------------------------------------------*/
- int
- findPlayer(
- long id
- )
- {
- int i ;
-
- for( i = ENEMY ; i < numberPlayers ; i++ )
- {
- if( player[i].id == id )
- {
- return( i ) ;
- }
- }
-
- return( 0 ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Delete a player.
- *----------------------------------------------------------------------------*/
- void
- deletePlayer(
- int i,
- char *verb
- )
- {
- int j ;
-
- postNewMessage( "%s %s.", player[i].name, verb ) ;
-
- if( networking ) {
- ngRemoveHostFromCensus( player[i].id ) ;
- ngDprintf( "%s: %s %s.\n", ngPrintTime(),
- ngHostNameFromId( player[i].id ), verb ) ;
- }
-
- deleteExplosion( i, mainScene ) ;
-
- while( pfGetNumChildren( trikeSwitch[i] ) )
- {
- pfRemoveChild( trikeSwitch[i],
- pfGetChild( trikeSwitch[i], 0 ) ) ;
- }
-
- pfRemoveChild( vehicleGroup, trike[i] ) ;
-
- for( j = i ; j < numberPlayers-1 ; j++ )
- {
- copyPlayer( j, &(player[j+1]) ) ;
- activity[j] = activity[j+1] ;
- pShield[j] = pShield[j+1] ;
- trike[j] = trike[j+1] ;
- trikeSwitch[j] = trikeSwitch[j+1] ;
- PFCOPY_VEC3( velocity[j], velocity[j+1] ) ;
- PFCOPY_VEC3( acceleration[j], acceleration[j+1] ) ;
- pfNodeTravData( trike[j], PFTRAV_ISECT, (void *)j ) ;
- }
-
- numberPlayers-- ;
- activity[numberPlayers] = 0 ;
-
- updatePlayerCounter() ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Reset function.
- *----------------------------------------------------------------------------*/
- void
- reset(
- void
- )
- {
- selfStatus = OORT_ST_CONFIGURING ;
- setMainDrawFunction() ;
-
- cloakOn = 0 ;
- selfDestruct = 0 ;
- latitude = 0.0f ;
- longitude = 0.0f ;
- speed = 0.0f ;
- shields = 1.0f ;
- power = 1.0f ;
- laser = 1.0f ;
- cloak = 1.0f ;
- laserCharge = 0.25f ;
- shieldRegenRate = 0.020f ;
- cloakRegenRate = 0.10f ;
- laserRegenRate = 1.0f / 3.0f ;
- pitch = 0.0f ;
- roll = 0.0f ;
- player[SELF].status = 0 ;
- player[SELF].hitById = 0 ;
- PFSET_VEC3( player[SELF].xyz, 0.0f, (float)(-10.0f * ASTEROID_RADIUS),
- 0.0f ) ;
- leftMouseHit = 0 ;
- rightMouseHit = 0 ;
-
- radarMaxRange() ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Print out a 4x4 matrix.
- *----------------------------------------------------------------------------*/
- void
- printMat(
- char *label,
- pfMatrix m
- )
- {
- int i ;
-
- printf( "%s\n", label ) ;
-
- for( i = 0 ; i < 4 ; i++ )
- {
- printf( "%10.6f %10.6f %10.6f %10.6f\n", m[i][0], m[i][1],
- m[i][2], m[i][3] ) ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Determine compass heading.
- *----------------------------------------------------------------------------*/
- float
- getHeading(
- void
- )
- {
- float d ;
- pfVec3 pos ;
- pfVec3 v ;
- pfVec3 east ;
- static pfVec3 north = { 0.0f, 0.0f, 1.0f } ;
-
- if( selfStatus == OORT_ST_ON_GROUND )
- {
- PFCOPY_VEC3( pos, motion.cg ) ;
- pos[2] = 0.0f ;
-
- if( pfNormalizeVec3( pos ) == 0.0f )
- {
- return( 0.0f ) ;
- }
-
- pfCrossVec3( east, north, pos ) ;
-
- d = -PFDOT_VEC3( pos, ahead ) ;
- v[0] = ahead[0] + d * pos[0] ;
- v[1] = ahead[1] + d * pos[1] ;
- v[2] = ahead[2] + d * pos[2] ;
-
- return( pfArcTan2( PFDOT_VEC3( v, east ),
- PFDOT_VEC3( v, north ) ) ) ;
- }
- else
- {
- return( 0.0f ) ;
- }
- }
-
-
-
-
- /*------------------------------------------------------------------------------
- * Print a label and a vector (debug).
- *----------------------------------------------------------------------------*/
- void
- printVec3(
- char *label,
- pfVec3 v
- )
- {
- printf( "%s: %f %f %f\n", label, v[0], v[1], v[2] ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Repaint compass background.
- *----------------------------------------------------------------------------*/
- static void
- repaintCompass(
- void
- )
- {
- static float tick[8][2] = {
- { 0.0f, 1.0f }, { 0.0f, 0.8f },
- { 0.0f, -1.0f }, { 0.0f, -0.8f },
- { 1.0f, 0.0f }, { 0.8f, 0.0f },
- { -1.0f, 0.0f }, { -0.8f, 0.0f },
- } ;
-
- viewport( headingVP.left, headingVP.right, headingVP.bottom,
- headingVP.top ) ;
- ortho2( -1.0f, 1.0f, -1.0f, 1.0f ) ;
- cpack( 0x0 ) ;
- clear() ;
- cpack( 0x00ffffff ) ;
- bgnline() ;
- v2f( tick[0] ) ;
- v2f( tick[1] ) ;
- endline() ;
- bgnline() ;
- v2f( tick[2] ) ;
- v2f( tick[3] ) ;
- endline() ;
- bgnline() ;
- v2f( tick[4] ) ;
- v2f( tick[5] ) ;
- endline() ;
- bgnline() ;
- v2f( tick[6] ) ;
- v2f( tick[7] ) ;
- endline() ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Initialize enemy structures.
- *----------------------------------------------------------------------------*/
- static void
- initEnemies(
- void
- )
- {
- int i ;
-
- for( i = SELF ; i < MAXPLAYERS ; i++ )
- {
- playerMatrix[i][0][3] = 0.0f ;
- playerMatrix[i][1][3] = 0.0f ;
- playerMatrix[i][2][3] = 0.0f ;
- playerMatrix[i][3][3] = 1.0f ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Transform a vector by a 4x4 matrix (v = v * m).
- *----------------------------------------------------------------------------*/
- static void
- vecMultMatInPlace(
- pfVec4 v,
- pfMatrix m
- )
- {
- pfVec4 a ;
- int i ;
- int j ;
-
- a[0] = v[0] ;
- a[1] = v[1] ;
- a[2] = v[2] ;
- a[3] = v[3] ;
-
- for( i = 0 ; i < 4 ; i++ )
- {
- v[i] = 0.0 ;
- for( j = 0 ; j < 4 ; j++ )
- {
- v[i] += a[j] * m[j][i] ;
- }
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Add a player.
- *----------------------------------------------------------------------------*/
- int
- addPlayer(
- Player *input
- )
- {
- int number ;
-
- if( numberPlayers <= MAXPLAYERS )
- {
- number = numberPlayers ;
- numberPlayers++ ;
- }
- else
- {
- fprintf( stderr, "%s: maximum number (%d) of players "
- "exceeded.\n", basename, MAXPLAYERS ) ;
- endProgram( 0 ) ;
- }
-
- copyPlayer( number, input ) ;
-
- trike[number] = pfNewDCS() ;
- pfAddChild( vehicleGroup, trike[number] ) ;
- trikeSwitch[number] = pfNewGroup() ;
- pfAddChild( trike[number], trikeSwitch[number] ) ;
-
- pfNodeTravMask( trike[number], PFTRAV_ISECT, LASER_MASK | VEHICLE_MASK,
- PFTRAV_SELF | PFTRAV_IS_CACHE, PF_SET ) ;
- pfAddChild( trikeSwitch[number],
- pfClone( vehicle[player[number].team], 0 ) ) ;
- if( ( pShield[number] = (pfGroup *)pfClone( shield, 0 ) ) == NULL )
- {
- fprintf( stderr, "%s: error cloning shield node\n", basename ) ;
- endProgram( 1 ) ;
- }
- pfAddChild( trikeSwitch[number], pShield[number] ) ;
- pfNodeTravMask( pShield[number], PFTRAV_DRAW, 0, PFTRAV_SELF, PF_SET ) ;
-
- pfNodeBSphere( trikeSwitch[number], vehicleBoundingSphere,
- PFN_BMODE_STATIC ) ;
-
- pfNodeTravFuncs( trikeSwitch[number], PFTRAV_ISECT,
- fireLaserPreTravCB, fireLaserPostTravCB ) ;
- pfNodeTravData( trikeSwitch[number], PFTRAV_ISECT, (void *)number ) ;
-
- addExplosion( number, mainScene ) ;
-
- PFSET_VEC3( velocity[number], 0.0f, 0.0f, 0.0f ) ;
- PFSET_VEC3( acceleration[number], 0.0f, 0.0f, 0.0f ) ;
-
- updatePlayerCounter() ;
-
- return( number ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Pick the landing site with the mouse.
- *----------------------------------------------------------------------------*/
- static int
- pickLandingSite(
- pfVec3 landingSite
- )
- {
- int st = 0 ;
- long flags ;
- pfHit **hits[1] ;
-
- doPick( (pfNode *)terrain, PFTRAV_IS_PRIM | PFPK_M_NEAREST,
- GROUND_MASK, hits ) ;
- pfQueryHit( hits[0][0], PFQHIT_FLAGS, &flags ) ;
-
- if( flags & PFHIT_POINT )
- {
- pfQueryHit( hits[0][0], PFQHIT_POINT, landingSite ) ;
- st = 1 ;
- }
- else
- {
- st = 0 ;
- }
-
- return( st ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Fire laser.
- *----------------------------------------------------------------------------*/
- static void
- fireLaser(
- void
- )
- {
- int i ;
- float ls ;
- float d ;
- pfHit **hits[1] ;
- long flags ;
- pfNode *node ;
-
- sfx( SFX_FIRE ) ;
-
- if( laser > laserCharge )
- {
- laser -= laserCharge ;
- ls = 1.0f ;
- }
- else
- {
- ls = laser / laserCharge ;
- laser = 0.0f ;
- }
-
- trikeHit = 0 ;
- checkTrike = 0 ;
- doPick( (pfNode *)terrainAndVehicles,
- PFTRAV_IS_PRIM | PFTRAV_IS_NO_PART, LASER_MASK, hits ) ;
- pfQueryHit( hits[0][0], PFQHIT_FLAGS, &flags ) ;
-
- if( ( flags & PFQHIT_NODE ) != 0 && trikeHit > 0 )
- {
-
- pfQueryHit( hits[0][0], PFQHIT_NODE, (float *)&node ) ;
- if( pfGetNodeTravMask( node, PFTRAV_ISECT ) & VEHICLE_MASK )
- {
- /*
- * Decrease laser effectiveness with distance.
- */
- d = pfSqrt( pfDistancePt3( player[SELF].xyz,
- player[trikeHit].xyz ) ) ;
- ls -= .050 * d ;
- if( ls < 0.0f )
- {
- ls = 0.0f ;
- }
-
- if( !networking )
- {
- pfNodeTravMask( pShield[trikeHit], PFTRAV_DRAW,
- 0xffffffff, PFTRAV_SELF, PF_SET ) ;
- player[trikeHit].status |=
- OORT_ST_SHIELDS ;
- player[SELF].laserStrength = 1 ;
- }
- else
- {
- player[SELF].hitId =
- player[trikeHit].id ;
- player[SELF].laserStrength =
- ls * 255 * laserFactor ;
- }
- }
- }
- else if( !networking )
- {
- player[SELF].laserStrength = 1 ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Pick a player to determine his name.
- *----------------------------------------------------------------------------*/
- static void
- pickPlayer(
- void
- )
- {
- long flags ;
- pfHit **hits[1] ;
-
- trikeHit = 0 ;
- checkTrike = 0 ;
- doPick( (pfNode *)terrainAndVehicles,
- PFTRAV_IS_PRIM | PFTRAV_IS_NO_PART, LASER_MASK, hits ) ;
- pfQueryHit( hits[0][0], PFQHIT_FLAGS, &flags ) ;
-
- if( ( flags & PFQHIT_NODE ) != 0 && trikeHit > 0 )
- {
- postNewMessage( "Looking at %s.", player[trikeHit].name ) ;
- sfx( SFX_OK ) ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Pre-traversal callback function when firing laser.
- *----------------------------------------------------------------------------*/
- static long
- fireLaserPreTravCB(
- pfTraverser *trav,
- void *data
- )
- {
- checkTrike = (int)data ;
- return( PFTRAV_CONT ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Post-traversal callback function when firing laser.
- *----------------------------------------------------------------------------*/
- static long
- fireLaserPostTravCB(
- pfTraverser *trav,
- void *data
- )
- {
- pfSphere sphere ;
- pfMatrix mat ;
-
- checkTrike = 0 ;
-
- return( PFTRAV_CONT | PFTRAV_IS_CLIP_END ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Load customizations from ~/.oortrc file.
- *----------------------------------------------------------------------------*/
- static void
- loadCustom(
- void
- )
- {
- int i ;
- int err ;
- FILE *f ;
- char *s ;
- char line[256] ;
- char path[MAXPATHLEN] ;
- static char *name = ".oortrc" ;
-
- /*
- * Try in current directory first.
- */
- sprintf( path, "./%s", name ) ;
- if( ( f = fopen( path, "r" ) ) == NULL )
- {
- /*
- * Try in home directory next.
- */
- if( getenv( "HOME" ) )
- {
- sprintf( path, "%s/%s", getenv( "HOME" ), name ) ;
- if( ( f = fopen( path, "r" ) ) == NULL )
- {
- /*
- * Couldn't find it.
- */
- noConfigFile( path ) ;
- return ;
- }
- }
- }
-
- while( fgets( line, 256, f ) != NULL )
- {
- /*
- * Skip comment lines.
- */
- if( line[0] == '#' )
- {
- continue ;
- }
-
- if( strncmp( line, "terrainColor:", 13 ) == 0 )
- {
- err = readColor( line+13, groundColor ) ;
- }
- else if( strncmp( line, "teamColorA:", 11 ) == 0 )
- {
- err = readColor( line+11, teamColor[0] ) ;
- }
- else if( strncmp( line, "teamColorB:", 11 ) == 0 )
- {
- err = readColor( line+11, teamColor[1] ) ;
- }
- else if( strncmp( line, "teamColorC:", 11 ) == 0 )
- {
- err = readColor( line+11, teamColor[2] ) ;
- }
- else if( strncmp( line, "teamColorD:", 11 ) == 0 )
- {
- err = readColor( line+11, teamColor[3] ) ;
- }
- else if( strncmp( line, "name:", 5 ) == 0 )
- {
- i = 5 ;
- while( isspace( line[i] ) )
- {
- i++ ;
- }
- strncpy( playerName, line+i, NAMELEN ) ;
- playerName[NAMELEN-1] = '\0' ;
- if( strlen( playerName ) == 0 )
- {
- err = 1 ;
- }
- else
- {
- if( ( s = strchr( playerName, '\n' ) ) != NULL )
- {
- *s = '\0' ;
- }
- }
- }
- else if( strncmp( line, "volume:", 7 ) == 0 )
- {
- if( sscanf( line+7, "%d", &initialVol ) != 1 ||
- initialVol < -1 || initialVol > 10 )
- {
- err = 1 ;
- }
- }
- else if( strncmp( line, "TTL:", 4 ) == 0 )
- {
- if( sscanf( line+4, "%d", &timeToLive ) != 1 ||
- timeToLive < NG_MIN_TTL ||
- timeToLive > NG_MAX_TTL )
- {
- err = 1 ;
- timeToLive = NG_DEFAULT_TTL ;
- }
- }
- else if( strncmp( line, "textLines:", 10 ) == 0 )
- {
- if( sscanf( line+10, "%d", &nTextLines ) != 1 ||
- nTextLines < 1 )
- {
- err = 1 ;
- }
- else if( nTextLines > MAX_TEXT_LINES )
- {
- nTextLines = MAX_TEXT_LINES ;
- }
- }
- else if( strncmp( line, "configuration:", 14 ) == 0 )
- {
- err = setDefaultConfig( line+14 ) ;
- }
- else
- {
- err = 0 ;
- fprintf( stderr, "%s: unknown entry in `%s'\n",
- basename, path ) ;
- fprintf( stderr, " -->%s", line ) ;
- }
-
- if( err )
- {
- fprintf( stderr, "%s: error in `%s'\n",
- basename, path ) ;
- fprintf( stderr, " -->%s", line ) ;
- }
- }
-
- fclose( f ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Read 3 floats from a string and store in a vector.
- *----------------------------------------------------------------------------*/
- static int
- readColor(
- char *s,
- pfVec3 v
- )
- {
- int err ;
- pfVec3 t ;
-
- if( sscanf( s, "%f %f %f", t+0, t+1, t+2 ) != 3 ||
- t[0] < 0.0f || 1.0f < t[0] ||
- t[1] < 0.0f || 1.0f < t[1] ||
- t[2] < 0.0f || 1.0f < t[2] )
- {
- err = 1 ;
- }
- else
- {
- PFCOPY_VEC3( v, t ) ;
- err = 0 ;
- }
-
- return( err ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Initialize a bunch o' stuff.
- *----------------------------------------------------------------------------*/
- static void
- initStuff(
- void
- )
- {
- pfPipe *p ;
-
- p = pfGetPipe(0);
- pfInitPipe( p, openPipe ) ;
-
- setupChannels( p ) ;
-
- starObj = makeBackground() ;
-
- makeRadarBackground( 9, 12 ) ;
-
- helpObj = makeHelpOverlay() ;
-
- initDashboard() ;
-
- defpattern( HALFTONE_PATTERN, 16, halftone ) ;
- defpattern( STATIC_PATTERN_0, 16, staticPattern[0] ) ;
- defpattern( STATIC_PATTERN_1, 16, staticPattern[1] ) ;
- defpattern( STATIC_PATTERN_2, 16, staticPattern[2] ) ;
-
- pfChanScene( mainChan, mainScene ) ;
-
- initEnemies() ;
-
- initConfigureScreen() ;
-
- initCom() ;
-
- if( initialVol > -1 )
- {
- initSound() ;
- if( initialVol < 11 )
- {
- setVolume( initialVol ) ;
- }
- }
-
- pfDisable( PFEN_FOG ) ;
- pfDisable( PFEN_TEXTURE ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Distribute power.
- *----------------------------------------------------------------------------*/
- static void
- distributePower(
- void
- )
- {
- float powerNeeded = 0.0f ;
- float powerAvail ;
- float shieldPowerNeeded ;
- float laserPowerNeeded ;
- float cloakPowerNeeded ;
-
- /*
- * Route power to engine.
- */
- power -= speedPowerReq() ;
- if( power < 0.0f )
- power = 0.0f ;
- powerAvail = eTime * 0.15f * solarRate ;
- if( powerAvail > power )
- powerAvail = power ;
-
- /*
- * Next, shields get as much power as needed.
- */
- shieldPowerNeeded = eTime * shieldRegenRate ;
- if( shieldPowerNeeded > 1.0f - shields )
- {
- shieldPowerNeeded = 1.0f - shields ;
- }
- if( powerAvail > shieldPowerNeeded )
- {
- shields += shieldPowerNeeded ;
- powerAvail -= shieldPowerNeeded ;
- power -= shieldPowerNeeded ;
- }
- else
- {
- shields += powerAvail ;
- power -= powerAvail ;
- powerAvail = 0.0f ;
- }
-
- /*
- * Next, lasers get as much power as needed.
- */
- laserPowerNeeded = eTime * laserRegenRate ;
- if( laserPowerNeeded > 1.0f - laser )
- {
- laserPowerNeeded = 1.0f - laser ;
- }
- if( powerAvail > laserPowerNeeded )
- {
- laser += laserPowerNeeded ;
- powerAvail -= laserPowerNeeded ;
- power -= laserPowerNeeded ;
- }
- else
- {
- laser += powerAvail ;
- power -= powerAvail ;
- powerAvail = 0.0f ;
- }
-
- /*
- * Drain power due to cloaking.
- */
- if( cloakOn )
- {
- cloak -= eTime * cloakRate ;
- if( cloak < 0.0f )
- {
- cloak = 0.0f ;
- cloakOn = 0 ;
- player[SELF].status &= ~OORT_ST_CLOAK ;
- }
- }
- else
- {
- /*
- * Whatever's left goes toward regenerating the cloaking device.
- */
- cloakPowerNeeded = eTime * cloakRegenRate ;
- if( cloakPowerNeeded > 1.0f - cloak )
- {
- cloakPowerNeeded = 1.0f - cloak ;
- }
- if( powerAvail > cloakPowerNeeded )
- {
- cloak += cloakPowerNeeded ;
- powerAvail -= cloakPowerNeeded ;
- power -= cloakPowerNeeded ;
- }
- else
- {
- cloak += powerAvail ;
- power -= powerAvail ;
- powerAvail = 0.0f ;
- }
- }
-
- /*
- * Regenerate power based on position. Take dot product of up
- * vector with sun vector (0,-1,0).
- */
- if( power < 1.0f )
- {
- if( up[1] < 0.0f )
- {
- power -= eTime * solarRate * up[1] ;
- }
- /*
- * Add in effect of "small nuclear power source".
- */
- power += eTime * 0.05f ;
- if( power > 1.0f )
- {
- power = 1.0f ;
- }
- }
-
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Calculate the power required for the current speed.
- *----------------------------------------------------------------------------*/
- float
- speedPowerReq(
- void
- )
- {
- float s ;
-
- if( speed > 0.0f )
- {
- s = speed ;
- }
- else
- {
- s = -speed ;
- }
-
- s /= topSpeed ;
-
- return( eTime * s * s * engineRate ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Front end to malloc routine that checks for valid allocation of memory.
- *----------------------------------------------------------------------------*/
- void *
- myMalloc(
- size_t nbytes
- )
- {
- void *p ;
-
- p = pfMalloc( nbytes, pfGetSharedArena() ) ;
-
- if( p == NULL )
- {
- fprintf( stderr, "out of memory\n" ) ;
- }
- return( p ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Post process players.
- *----------------------------------------------------------------------------*/
- static void
- postProcessPlayers(
- void
- )
- {
- int i ;
-
- for( i = ENEMY ; i < numberPlayers ; i++ )
- {
- pfNodeTravMask( pShield[i], PFTRAV_DRAW, 0, PFTRAV_SELF,
- PF_SET ) ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Post process players in demo mode.
- *----------------------------------------------------------------------------*/
- static void
- demoPostProcessPlayers(
- void
- )
- {
- postProcessPlayers() ;
-
- if( newSelfStatus != selfStatus )
- {
- selfStatus = newSelfStatus ;
-
- switch( selfStatus )
- {
- case OORT_ST_IN_ORBIT :
- shields = 1.0f ;
- power = 1.0f ;
- break ;
-
- case OORT_ST_EXIT :
- selfStatus = OORT_ST_CONFIGURING ;
- shields = 1.0f ;
- power = 1.0f ;
- break ;
- }
-
- setMainDrawFunction() ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Blow self up.
- *----------------------------------------------------------------------------*/
- void
- blowUpSelf(
- int hitId
- )
- {
- shields = 0.0f ;
- speed = 0.0f ;
- power = 0.0f ;
- player[SELF].score -= 1 ;
- addLife() ;
- player[SELF].hitById = hitId ;
- selfStatus = OORT_ST_DEAD ;
- player[SELF].status &= ~( OORT_ST_SHIELDS | OORT_ST_IDLE_HIT ) ;
- player[SELF].status |= OORT_ST_EXPLODING ;
- deadTime[SELF] = gameTime ;
- sfx( SFX_STATIC ) ;
- setMainDrawFunction() ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Toggle cloaking on and off.
- *----------------------------------------------------------------------------*/
- void
- toggleCloaking(
- void
- )
- {
- if( cloakOn )
- {
- if( cloak > 0.0f )
- {
- player[SELF].status |= OORT_ST_CLOAK ;
- }
- else
- {
- cloakOn = 0 ;
- }
- }
- else
- {
- player[SELF].status &= ~OORT_ST_CLOAK ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Set the main channel draw callback function.
- *----------------------------------------------------------------------------*/
- void
- setMainDrawFunction(
- void
- )
- {
- if( selfStatus == OORT_ST_CONFIGURING )
- {
- pfChanDrawFunc( mainChan, drawConfigureScreen ) ;
- }
- else if( selfStatus == OORT_ST_DEAD )
- {
- pfChanDrawFunc( mainChan, drawStaticScreen ) ;
- }
- else
- {
- pfChanDrawFunc( mainChan, drawMainChannel ) ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Define and set the cursor.
- *----------------------------------------------------------------------------*/
- static void
- initCursor(
- void
- )
- {
- if( getgdesc( GD_BITS_CURSOR ) > 1 )
- {
- curstype( C16X2 ) ;
- defcursor( 1, cursorBitMap2 ) ;
- drawmode( CURSORDRAW ) ;
- mapcolor( 1, 255, 255, 0 ) ;
- drawmode( NORMALDRAW ) ;
- }
- else
- {
- curstype( C16X1 ) ;
- defcursor( 1, cursorBitMap1 ) ;
- drawmode( CURSORDRAW ) ;
- mapcolor( 1, 255, 255, 0 ) ;
- mapcolor( 2, 0, 0, 0 ) ;
- mapcolor( 3, 0, 0, 0 ) ;
- drawmode( NORMALDRAW ) ;
- }
- curorigin( 1, 8, 8 ) ;
- setcursor( 1, 0, 0 ) ;
-
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Take shield damage.
- *----------------------------------------------------------------------------*/
- void
- shieldDamage(
- float strength,
- int id
- )
- {
- int n ;
-
- if( selfStatus == OORT_ST_ON_GROUND )
- {
- sfx( SFX_HIT ) ;
-
- shields -= 0.50 * strength / shieldFactor ;
- if( shields < 0.0f )
- {
- blowUpSelf( id ) ;
- if( id != 0 )
- {
- n = findPlayer( id ) ;
- postNewMessage( "Killed by %s.",
- player[n].name ) ;
- }
- else
- {
- postNewMessage( "Killed by orbital fortress." );
- }
- }
- else
- {
- player[SELF].status |= OORT_ST_SHIELDS ;
- if( id == 0 )
- {
- postNewMessage( "Orbital fortress has locked "
- "on." ) ;
- }
- }
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Find a file in the default directory or according to environment variables.
- *----------------------------------------------------------------------------*/
- char *
- findFile(
- char *file
- )
- {
- char *dir ;
- char *path ;
-
- if( ( dir = getenv( "OORT_DIR" ) ) == NULL )
- {
- dir = DATA_DIR ;
- }
- path = malloc( strlen( dir ) + strlen( file ) + 2 ) ;
-
- sprintf( path, "%s/%s", dir, file ) ;
-
- return( path ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * The main loop.
- *----------------------------------------------------------------------------*/
- static void
- mainLoop(
- void
- )
- {
- float lastTime ;
- static float alarmTime = 0.0f ;
-
- while( stayInProgram )
- {
- while( selfStatus == OORT_ST_ON_GROUND )
- {
- /* Go to sleep till next frame time */
- pfSync() ;
-
- gameTime = pfGetTime() ;
- eTime = gameTime - lastTime ;
- lastTime = gameTime ;
-
- if( shields < 0.25f && gameTime - alarmTime > 2.0f )
- {
- alarmTime = gameTime ;
- sfx( SFX_ALARM ) ;
- }
-
- moveSelf( terrain ) ;
-
- if( gameTime - idleStartTime > 5.0f )
- {
- player[SELF].status |= OORT_ST_IDLE_HIT ;
- idleStartTime += 2.0f ;
- shieldDamage( 0.50f, 0 ) ;
- }
- else
- {
- player[SELF].status &= ~OORT_ST_IDLE_HIT ;
- }
-
- getLatLong() ;
-
- writePackets() ;
- player[SELF].status &= ~OORT_ST_SHIELDS ;
- readPackets() ;
-
- updateViewGround() ;
-
- distributePower() ;
-
- pfFrame();
-
- postProcessPlayers() ;
-
- if( leftMouseHit )
- {
- fireLaser() ;
- leftMouseHit = 0 ;
- }
-
- if( rightMouseHit )
- {
- pickPlayer() ;
- rightMouseHit = 0 ;
- }
-
- if( selfDestruct )
- {
- if( gameTime - selfDestructTime >= 10.0f )
- {
- blowUpSelf( 0 ) ;
- }
- else if( gameTime - selfDestructAlarmTime >
- 2.0f )
- {
- selfDestructAlarmTime = gameTime ;
- sfx( SFX_ALARM ) ;
- }
- }
- }
-
- while( selfStatus == OORT_ST_IN_ORBIT )
- {
- /* Go to sleep till next frame time */
- pfSync() ;
-
- gameTime = pfGetTime() ;
- eTime = gameTime - lastTime ;
- lastTime = gameTime ;
-
- writePackets() ;
- player[SELF].status &= ~OORT_ST_SHIELDS ;
- readPackets() ;
-
- updateViewInOrbit() ;
-
- pfFrame();
-
- postProcessPlayers() ;
- }
-
- while( selfStatus == OORT_ST_DEAD )
- {
- /* Go to sleep till next frame time */
- pfSync() ;
-
- gameTime = pfGetTime() ;
- eTime = gameTime - lastTime ;
- lastTime = gameTime ;
-
- writePackets() ;
- player[SELF].status &= ~OORT_ST_SHIELDS ;
- readPackets() ;
-
- updateViewGround() ;
-
- pfFrame();
-
- postProcessPlayers() ;
-
- if( gameTime - deadTime[SELF] > 5.0f )
- {
- reset() ;
- }
- else
- {
- power = ( gameTime - deadTime[SELF] ) / 5.0f ;
- }
- }
-
- while( selfStatus == OORT_ST_CONFIGURING )
- {
- /* Go to sleep till next frame time */
- pfSync() ;
-
- gameTime = pfGetTime() ;
- eTime = gameTime - lastTime ;
- lastTime = gameTime ;
-
- writePackets() ;
- player[SELF].status &= ~OORT_ST_SHIELDS ;
- readPackets() ;
-
- pfFrame();
-
- postProcessPlayers() ;
- }
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Channel draw callback - draw dead screen.
- *----------------------------------------------------------------------------*/
- static void
- drawStaticScreen(
- pfChannel *channel,
- void *data
- )
- {
- float x ;
- float y ;
- static char *msg = "Signal lost." ;
-
- /*
- * Get input.
- */
- grabInput() ;
-
- pfPushState() ;
- pfBasicState() ;
-
- zfunction( ZF_ALWAYS ) ;
- zwritemask( 0x0 ) ;
- if( gameTime - deadTime[SELF] > 0.5f )
- {
- if( mainVP.right - mainVP.left > mainVP.top - mainVP.bottom )
- {
- y = mainVP.top - mainVP.bottom ;
- x = (float)( mainVP.right - mainVP.left ) / y ;
- y = 1.0f ;
- }
- else
- {
- x = mainVP.right - mainVP.left ;
- y = (float)( mainVP.top - mainVP.bottom ) / x ;
- x = 1.0f ;
- }
-
- pfPushIdentMatrix() ;
- ortho2( -x, x, -y, y ) ;
- cpack( 0x0 ) ;
- clear() ;
- cpack( 0x00ff ) ;
- positionText( -0.5f * getStrWidth( helvFont, msg ), 0.0f ) ;
- drawString( helvFont, msg ) ;
- pfPopMatrix() ;
- }
- else
- {
- drawStaticDisplay() ;
- }
- zfunction( ZF_LEQUAL ) ;
- zwritemask( 0xffffffff ) ;
-
- pfPopState();
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Draw static on the screen.
- *----------------------------------------------------------------------------*/
- static void
- drawStaticDisplay(
- void
- )
- {
- static int cIndex = 0 ;
- static int pIndex = 0 ;
- int i ;
- float dy = 0.3f ;
- float y ;
- pfVec2 l ;
- pfVec2 r ;
-
- pfPushIdentMatrix() ;
- ortho2( 0.0f, 1.0f, 0.0f, 1.0f ) ;
- cpack( 0x00ff ) ;
- clear() ;
- y = -dy - 0.1f - ( rand() % 3 ) * 0.05 ;
- pIndex = 0 ;
- while( y < 1.0f )
- {
- for( i = 0 ; i < 3 ; i++ )
- {
- cIndex = ( cIndex + 1 ) % 3 ;
- pIndex = ( pIndex + 1 ) % 3 ;
- cpack( staticColor[cIndex] ) ;
- setpattern( STATIC_PATTERN_0 + pIndex ) ;
- bgntmesh() ;
- PFSET_VEC2( l, 0.0f, y ) ;
- PFSET_VEC2( r, 1.0f, y + dy ) ;
- v2f( l ) ;
- v2f( r ) ;
- PFSET_VEC2( l, 0.0f, y + 0.1f ) ;
- PFSET_VEC2( r, 1.0f, y + 0.1f + dy ) ;
- v2f( l ) ;
- v2f( r ) ;
- endtmesh() ;
- }
- cIndex = ( cIndex + 1 ) % 3 ;
- y += 0.1f ;
- }
- setpattern( 0 ) ;
-
- cIndex = ( cIndex + 1 + rand() % 2 ) % 3 ;
- pIndex = ( pIndex + 2 ) % 3 ;
-
- pfPopMatrix() ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * The demo main loop.
- *----------------------------------------------------------------------------*/
- static void
- demoMainLoop(
- void
- )
- {
- float lastTime ;
- static float alarmTime = 0.0f ;
-
- while( stayInProgram )
- {
- while( selfStatus == OORT_ST_ON_GROUND )
- {
- /* Go to sleep till next frame time */
- pfSync() ;
-
- gameTime = pfGetTime() ;
- eTime = gameTime - lastTime ;
- lastTime = gameTime ;
-
- if( shields < 0.25f && gameTime - alarmTime > 2.0f )
- {
- alarmTime = gameTime ;
- sfx( SFX_ALARM ) ;
- }
-
- getLatLong() ;
-
- writePackets() ;
- readPackets() ;
-
- updateViewGround() ;
-
- distributePower() ;
-
- pfFrame();
-
- demoPostProcessPlayers() ;
- }
-
- while( selfStatus == OORT_ST_IN_ORBIT )
- {
- /* Go to sleep till next frame time */
- pfSync() ;
-
- gameTime = pfGetTime() ;
- eTime = gameTime - lastTime ;
- lastTime = gameTime ;
-
- writePackets() ;
- readPackets() ;
-
- updateViewInOrbit() ;
-
- pfFrame();
-
- demoPostProcessPlayers() ;
- }
-
- while( selfStatus == OORT_ST_DEAD )
- {
- /* Go to sleep till next frame time */
- pfSync() ;
-
- gameTime = pfGetTime() ;
- eTime = gameTime - lastTime ;
- lastTime = gameTime ;
-
- writePackets() ;
- readPackets() ;
-
- updateViewGround() ;
-
- pfFrame();
-
- demoPostProcessPlayers() ;
-
- if( gameTime - deadTime[SELF] > 5.0f )
- {
- reset() ;
- }
- else
- {
- power = ( gameTime - deadTime[SELF] ) / 5.0f ;
- }
- }
-
- while( selfStatus == OORT_ST_CONFIGURING )
- {
- /* Go to sleep till next frame time */
- pfSync() ;
-
- gameTime = pfGetTime() ;
- eTime = gameTime - lastTime ;
- lastTime = gameTime ;
-
- writePackets() ;
- readPackets() ;
-
- pfFrame();
-
- demoPostProcessPlayers() ;
- }
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Comparison function for sorting scores.
- *----------------------------------------------------------------------------*/
- static int
- compareScores(
- const void *p1,
- const void *p2
- )
- {
- int i1 = *(int *)p1 ;
- int i2 = *(int *)p2 ;
-
- if( player[i1].score < player[i2].score )
- return( 1 ) ;
- else if( player[i1].score > player[i2].score )
- return( -1 ) ;
- else
- return( 0 ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Show scores.
- *----------------------------------------------------------------------------*/
- void
- listScores(
- void
- )
- {
- int i ;
- int n ;
- int place ;
- int p[MAXPLAYERS] ;
-
- if( nTextLines < 4 )
- {
- postNewMessage( "Not enough text lines." ) ;
- return ;
- }
-
- for( i = 0 ; i < numberPlayers ; i++ )
- {
- p[i] = i ;
- }
-
- qsort( (void *)p, numberPlayers, sizeof( p[0] ), compareScores ) ;
-
- place = 0 ;
- for( i = 0 ; i < numberPlayers ; i++ )
- {
- if( p[i] == SELF )
- {
- place = i + 1 ;
- break ;
- }
- }
-
- n = nTextLines - 3 ;
- if( n > numberPlayers )
- {
- n = numberPlayers ;
- }
- postNewMessage( "Your score: %d (%d of %d)", player[SELF].score,
- place, numberPlayers ) ;
- postNewMessage( "Top %d scores:", n ) ;
-
- for( i = 0 ; i < n ; i++ )
- {
- postNewMessage( "%-12s %3d", player[p[i]].name,
- player[p[i]].score ) ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * No config file was found, so launch showcase help and create a default
- * config file in the home directory.
- *----------------------------------------------------------------------------*/
- static void
- noConfigFile(
- char *name
- )
- {
- int i ;
- FILE *f ;
-
- if( ( f = fopen( name, "w" ) ) == NULL )
- {
- perror( name ) ;
- fprintf( stderr, "%s: could not create default configuration "
- "file.\n", basename ) ;
- }
- else
- {
- for( i = 0 ; i < 6 ; i++ )
- {
- fputs( defaultConfigText[i], f ) ;
- }
-
- fclose( f ) ;
-
- fprintf( stderr, "%s: created %s.\n", basename, name ) ;
- }
-
- displayHelp() ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Show the showcase help cards.
- *----------------------------------------------------------------------------*/
- static void
- displayHelp(
- void
- )
- {
- char *helpFile ;
- char *cmd ;
- static int seen = 0 ;
-
- if( seen == 1 )
- return ;
-
- seen = 1 ;
-
- helpFile = findFile( "oort_help.showcase" ) ;
-
- if( ( cmd = malloc( strlen( helpFile ) + 20 ) ) == NULL )
- {
- fprintf( stderr, "%s: out of memory -- could not start help "
- "file.\n", basename ) ;
- }
- else if( access( helpFile, R_OK ) == 0 )
- {
- if( getgdesc( GD_BITS_NORM_DBL_RED ) < 4 )
- {
- sprintf( cmd, "showcase -b -f -v %s", helpFile ) ;
- }
- else
- {
- sprintf( cmd, "showcase -f -v %s", helpFile ) ;
- }
- system( cmd ) ;
- free( cmd ) ;
- }
- else
- {
- perror( helpFile ) ;
- }
-
- free( helpFile ) ;
- }
-
-
-
- static char *helpLine[] = {
- "Help Summary",
- "ESCAPE - exit game",
- "a/z - unzoom/zoom radar",
- "uparrow - increase volume",
- "downarrow - decrease volume",
- "s - show score",
- "h - toggle help screen",
- "i - show config info",
- "m - send broadcast message",
- "t - send team message",
- "f1 - show performance stats",
- "f2 - toggle terrain texture",
- "",
- "IN ORBIT",
- "leftmouse - pick landing site",
- "middlemouse - rotate Oort",
- "",
- "ON GROUND",
- "leftmouse - fire laser",
- "rightmouse - identify player",
- "space - apply brakes",
- "r - positive acceleration",
- "e - small positive acceleration",
- "w - small negative acceleration",
- "q - negative acceleration",
- "b - start/stop self destruct",
- "c - toggle ECM",
- "l - print lat/long location",
- } ;
-
- /*------------------------------------------------------------------------------
- * Make object for displaying text.
- *----------------------------------------------------------------------------*/
- static Object
- makeHelpOverlay(
- void
- )
- {
- int i ;
- int nLines ;
- Object objectNo ;
- float fontSize ;
- float y ;
-
- objectNo = genobj() ;
-
- nLines = sizeof( helpLine ) / sizeof( helpLine[0] ) ;
- helpFont = copyFont( helvFont ) ;
- fontSize = 2.0f / ( nLines + 3 ) ;
-
- y = 1.0f - 2.0f * fontSize ;
- makeobj( objectNo ) ;
- setFontSize( helpFont, 1.5f * fontSize ) ;
- positionText( -0.5f * getStrWidth( helpFont, helpLine[0] ), y );
- drawString( helpFont, helpLine[0] ) ;
- y -= 2.0f * fontSize ;
- setFontSize( helpFont, fontSize ) ;
- for( i = 1 ; i < nLines ; i++ )
- {
- positionText( -0.5f *
- getStrWidth( helpFont, helpLine[i] ), y ) ;
- drawString( helpFont, helpLine[i] ) ;
- y -= fontSize ;
- }
- closeobj() ;
-
- return( objectNo ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Check for minimum system requirements.
- *----------------------------------------------------------------------------*/
- static void
- checkMinReqs(
- void
- )
- {
- /*
- * Make sure we have a z-buffer and can run in RGB mode.
- */
- if( getgdesc( GD_BITS_NORM_ZBUFFER ) == 0 )
- {
- fprintf( stderr, "%s: no z-buffer available.\n", basename ) ;
- exit( 1 ) ;
- }
-
- /*
- * Make sure we can run in RGB mode.
- */
- if( getgdesc( GD_BITS_NORM_DBL_RED ) == 0 ||
- getgdesc( GD_BITS_NORM_DBL_GREEN ) == 0 ||
- getgdesc( GD_BITS_NORM_DBL_BLUE ) == 0 )
- {
- fprintf( stderr, "%s: double-buffer RGB mode not supported.\n",
- basename ) ;
- exit( 1 ) ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Discriminator callback function for intersections.
- *----------------------------------------------------------------------------*/
- static long
- pickDiscFunc(
- pfHit *hit
- )
- {
- if( checkTrike > 0 )
- {
- trikeHit = checkTrike ;
- }
-
- return( PFTRAV_CONT | PFTRAV_IS_CLIP_END ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Replacement function for pfChanPick -- does a pfSegsIsectNode on the
- * main channel from the eye position through the cursor position.
- *----------------------------------------------------------------------------*/
- static void
- doPick(
- pfNode *root,
- long mode,
- long mask,
- pfHit **hits[]
- )
- {
- pfVec3 eye ;
- pfVec3 ll ;
- pfVec3 lr ;
- pfVec3 ul ;
- pfVec3 ur ;
- pfVec3 v ;
- pfVec3 h ;
- pfSegSet segSet ;
- pfSeg iSegs[1] ;
-
- pfGetFrustEye( mainChan, eye ) ;
- pfGetFrustFar( mainChan, ll, lr, ul, ur ) ;
- PFSUB_VEC3( v, lr, ll ) ;
- ADDSCALE_VEC3( v, ll, pickX, v ) ;
- PFSUB_VEC3( h, ul, ll ) ;
- ADDSCALE_VEC3( v, v, pickY, h ) ;
- pfMakePtsSeg( &(segSet.segs[0]), eye, v ) ;
- segSet.activeMask = 0x01 ;
- segSet.mode = mode ;
- segSet.isectMask = mask ;
- segSet.bound = NULL ;
- segSet.discFunc = NULL ;
- segSet.userData = NULL ;
- segSet.discFunc = pickDiscFunc ;
-
- pfSegsIsectNode( root, &segSet, hits ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Initialize the shield geometries.
- *----------------------------------------------------------------------------*/
- static void
- initShield(
- void
- )
- {
- int i ;
-
- if( ( shield = loadOortShield( "shield.data" ) ) == NULL )
- {
- endProgram( 1 ) ;
- }
-
- if( ( vehicleBoundingSphere = myMalloc( sizeof( pfSphere ) ) ) == NULL )
- {
- endProgram( 1 ) ;
- }
-
- PFSET_VEC3( vehicleBoundingSphere->center, 0.0f, 0.0f, 0.0f ) ;
- vehicleBoundingSphere->radius = 2.5f ;
-
- pfNodeBSphere( shield, vehicleBoundingSphere,
- PFN_BMODE_STATIC ) ;
-
- for( i = 0 ; i < N_TEAMS ; i++ )
- {
- pfNodeBSphere( vehicle[i], vehicleBoundingSphere,
- PFN_BMODE_STATIC ) ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Draw laser strikes from obital fortresses.
- *----------------------------------------------------------------------------*/
- static void
- drawOrbitalFortressStrikes(
- void
- )
- {
- int i ;
- pfVec3 top ;
-
- for( i = ENEMY ; i < numberPlayers ; i++ )
- {
- if( player[i].status & OORT_ST_IDLE_HIT )
- {
- PFSCALE_VEC3( top, 3.0f, player[i].xyz ) ;
- cpack( 0x0000ff00 ) ;
- bgnline() ;
- v3f( top ) ;
- v3f( player[i].xyz ) ;
- endline() ;
- player[i].status &= ~OORT_ST_IDLE_HIT ;
- }
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Draw title screen.
- *----------------------------------------------------------------------------*/
- static void
- drawTitle(
- void
- )
- {
- float x ;
- float y ;
- Screencoord l ;
- Screencoord r ;
- Screencoord b ;
- Screencoord t ;
- static GeoFont *tf = NULL ;
- static char *title = "OORT" ;
- static char *version = "1.1" ;
- static char *motd = "See help screen for key changes." ;
-
- pfPushIdentMatrix() ;
- reshapeviewport() ;
- getviewport( &l, &r, &b, &t ) ;
-
- zfunction( ZF_ALWAYS ) ;
- zwritemask( 0x0 ) ;
-
- if( tf == NULL )
- {
- tf = copyFont( helvFont ) ;
- }
-
- if( r - l > t - b )
- {
- y = t - b ;
- x = (float)( r - l ) / y ;
- y = 1.0f ;
- }
- else
- {
- x = r - mainVP.left ;
- y = (float)( t - b ) / x ;
- x = 1.0f ;
- }
-
- ortho2( -x, x, -y, y ) ;
- cpack( 0x0 ) ;
- clear() ;
- cpack( 0x00ff ) ;
- setFontSize( tf, 0.4f ) ;
- positionText( -0.5f * getStrWidth( tf, title ), 0.0f ) ;
- drawString( tf, title ) ;
- setFontSize( tf, 0.2f ) ;
- positionText( -0.5f * getStrWidth( tf, version ), -0.25f ) ;
- drawString( tf, version ) ;
- setFontSize( tf, 0.1f ) ;
- positionText( -0.5f * getStrWidth( tf, motd ), -0.375f ) ;
- drawString( tf, motd ) ;
-
- zfunction( ZF_LEQUAL ) ;
- zwritemask( 0xffffffff ) ;
-
- pfPopMatrix() ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Toggle texturing on/off.
- *----------------------------------------------------------------------------*/
- int
- toggleTexturing(
- void
- )
- {
- static mode = 1 ;
-
- if( terrainTextured )
- {
- if( mode )
- {
- pfDisable(PFEN_TEXTURE);
- pfOverride(PFSTATE_ENTEXTURE, PF_ON) ;
- postNewMessage( "Textures disabled." ) ;
- mode = 0 ;
- }
- else
- {
- pfEnable(PFEN_TEXTURE);
- pfOverride(PFSTATE_ENTEXTURE, PF_OFF) ;
- postNewMessage( "Textures enabled." ) ;
- mode = 1 ;
- }
- }
- else
- {
- postNewMessage( "No texture data available." ) ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Try to determine if hardware texturing is available. This is really
- * cheesy because it will have to be updated when new hardware becomes
- * available.
- *----------------------------------------------------------------------------*/
- static void
- checkGraphicsHw( void )
- {
- int i ;
- int doTex = 0 ;
- char buf[64] ;
- static char *texGraphicsHw[] = { "GTX", "VGX", "RE" } ;
-
- gversion( buf ) ;
-
- for( i = 0 ; i < sizeof( texGraphicsHw ) / sizeof( texGraphicsHw[0] ) ;
- i++ )
- {
- if( strstr( buf, texGraphicsHw[i] ) != NULL )
- {
- doTex = 1 ;
- break ;
- }
- }
-
- if( doTex == 0 )
- {
- toggleTexturing() ;
- }
- }
-
-